//
//  main.m
//  Demo0011
//
//  Created by zTercel on 13-1-4.
//  Copyright (c) 2013年 zTercel. All rights reserved.
//

#import <Foundation/Foundation.h>

void ShapeDataStruct()
{
    // about gui datastruct
    NSRange range = {10, 4};
    range = NSMakeRange(100, 12);
    NSRect rect = NSMakeRect(10, 10, 200, 200);
    rect.origin = NSMakePoint(101, 101);
    rect.size   = NSMakeSize(20, 20);
    NSLog(@"rect(%.f, %.f, %.f, %.f) range(%ld, %ld)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, range.location, range.length);
    
    return;
}

void NumberClass()
{ 
    NSNumber* boolNumber    = [[NSNumber alloc] initWithBool: YES];
    NSNumber* intNumber     = [[NSNumber alloc] initWithInt: 100];
    NSNumber* longNumber    = [[NSNumber alloc] initWithLong: 10000000];
    NSNumber* charNumber    = [[NSNumber alloc] initWithChar: 'c'];
    NSNumber* doubleNumber  = [[NSNumber alloc] initWithDouble: 10000000.01232333];
    NSNumber* floatNumber   = [[NSNumber alloc] initWithInt: 200000];
    floatNumber = [NSNumber numberWithDouble: 10121.123121];
    
    NSLog(@"boolNumber: %d",    [boolNumber boolValue]);
    NSLog(@"intNumber: %d",     [intNumber intValue]);
    NSLog(@"longNumber: %ld",   [longNumber longValue]);
    NSLog(@"charNumber: %d",    [charNumber charValue]);
    NSLog(@"doubleNumber: %f",  [doubleNumber doubleValue]);
    NSLog(@"floatNumber: %f",   [floatNumber floatValue]);
    
    NSLog(@"%@", longNumber);
   
    NSLog(@"value: %f", [doubleNumber doubleValue] + [longNumber longValue]);

    return;
}

void NumberUsing()
{
    NSNumber* number1   = [[NSNumber alloc] initWithInt: 100];      //  set value method:  initWithXXXX
    NSNumber* number2   = [NSNumber numberWithInt: 1000];           //  set value method:  numberWithXXXX
    NSLog(@"number1 = %@ number2 = %@  number1 + number2 = %d", number1, number2, ([number1 intValue] + [number2 intValue]));   // get value method:  xxxValue
    
    BOOL result = [number1 isEqualToNumber: number2];               // compare method: isEqualNumber
 
    NSLog(@"number1(%@) == number2(%@)? %s", [number1 stringValue], [number2 descriptionWithLocale: nil], result ? "yes" : "no");  // get value method: stringValue, descriptionWithLocale
   
    NSLog(@"number objType = %s", [number1 objCType]);
   
    switch ([number1 compare: number2]) {                           // compare method: compare
        case NSOrderedAscending:
            NSLog(@"number1(%@) < number2(%@)",  number1, number2);
            break;
        case NSOrderedDescending:
            NSLog(@"number1(%@) > number2(%@)", number1, number2);
            break;
        case NSOrderedSame:
            NSLog(@"number1(%@) = number2(%@)", number1, number2);
            break;
        default:
            break;
    } 
    
    return;
}

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        
        ShapeDataStruct();
        
        NumberClass();
        
        NumberUsing();
    }
    return 0;
}

